import { createRouter, createWebHistory } from "vue-router";
import { getDeviceSign } from "@/components/getDeviceSign";

const routes = [
  {
    path: "/",
    name: "layout",
    redirect: "/" + getDeviceSign(),
    children: [
      {
        path: "/m",
        name: "mLayout",
        component: () => import("../layout/m_Layout.vue"),
        redirect: () => {
          return { name: "mHome" };
        },
        children: [
          {
            path: "1001",
            name: "mHome",
            component: () => import("@/views/m_Home.vue"),
          },
          {
            path: "1002",
            name: "mSendNotice",
            component: () => import("@/views/m_SendNotice.vue"),
          },
          {
            path: "1003",
            name: "mCenter",
            component: () => import("@/views/m_Center.vue"),
          },
          {
            path: "1004",
            name: "mNotificationDetail",
            component: () => import("@/views/m_NotificationDetail.vue"),
          },
          {
            path: "1005",
            name: "mAllSendNotification",
            component: () => import("@/views/m_AllSendNotice.vue"),
          },
        ],
      },
      {
        path: "/login",
        name: "mlogin",
        component: () => import("../views/m_Login.vue"),
      },
    ],
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

router.beforeEach((to, from, next) => {
    // if (localStorage.getItem("openId")==null) {
    //   location.replace("/login")
    // }else {
    //   next()
    // }

  sessionStorage.setItem(
    "pageNo",
    to.path.substring(to.path.lastIndexOf("/") + 1)
  );
  next();
});

export default router;
